package com.zx.jhpt.service;

import com.zx.framework.core.exception.ServiceException;
import com.zx.framework.core.pagination.Pagination;
import com.zx.framework.core.util.DatetimeUtils;
import com.zx.framework.core.util.RandomUtil;
import com.zx.framework.core.util.SQLBuilder;
import com.zx.framework.core.util.StringUtil;
import com.zx.framework.db.IBaseDAO;
import com.zx.framework.plat.dept.po.Dept;
import com.zx.framework.plat.dept.service.DeptService;
import com.zx.framework.plat.user.po.User;
import com.zx.jhpt.excel.Engine;
import com.zx.jhpt.excel.vo.Risk;
import com.zx.jhpt.po.*;
import com.zx.jhpt.util.DeptCache;
import com.zx.jhpt.util.FxdCache;
import com.zx.jhpt.vo.JhptConts;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service("marketEngineService")
@Transactional
public class MarketEngineService {
	private static final Logger LOGGER = Logger.getLogger(MarketEngineService.class);
	@Resource
	private IBaseDAO baseDAO;
	
	/**
	 * 执行建表语句
	 * @param sql
	 * @return
	 */
	public int executeCreateSQL(final String sql){
		String[] sqlArr = sql.split(";");
		for (String string : sqlArr) {
			if(StringUtil.isNotBlank(string)){
				baseDAO.executeSQL(string);
			}
		}
		return sqlArr.length;
	}
	/**
	 * 判断表是否存在
	 * @param tbName
	 * @return
	 */
	public boolean exists(String tbName){
		String sql  = "select count(*) from user_tables where table_name like ?";
		return baseDAO.getSQLUnique(sql, BigDecimal.class, tbName).intValue() !=0;
	}
}
